class Solution
{
public:
    string addBinary(string a, string b)
    {
        string ret;
        int up = a.size() - 1, down = b.size() - 1, t = 0;
        while (up >= 0 || down >= 0 || t)
        {
            if (up >= 0) t += a[up--] - '0';
            if (down >= 0) t += b[down--] - '0';
            ret += t % 2 + '0';
            t = t / 2;
        }
        reverse(ret.begin(), ret.end());
        return ret;
    }
};